package RKUjava.awt;
import java.awt.Container;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Font;
import java.awt.GridBagLayout;


/** This class defines a number of useful methods for working with javas AWT. */
public class AWTutil
{

  /** Constrain a component within a container. */
  public static void constrain(Container container, Component component, int grid_x, int grid_y, int grid_width, int grid_height, int fill, int anchor, double weight_x, double weight_y,int top, int left, int bottom, int right)
  {
    GridBagConstraints c = new GridBagConstraints();

    c.gridx = grid_x;
    c.gridy = grid_y;
    c.gridwidth = grid_width;
    c.gridheight = grid_height;
    c.fill = fill;
    c.anchor = anchor;
    c.weightx = weight_x;
    c.weighty = weight_y;
    
    if (top+bottom+left+right>0)
      {
	c.insets = new Insets(top,left,bottom,right);
      }
    ((GridBagLayout)container.getLayout()).setConstraints(component,c);
    container.add(component);
  }

  /** Set all fonts on a container to a specific font. (Much easier than 
      doing it by hand.)
  */
  public static void setFonts(Container container, Font font)
    {
      Component[] components = container.getComponents();
      int i;
      
      for(i=0;i<components.length;i++) {
	components[i].setFont(font);
      }
    }
}
